// pages/admin/dashboard/dashboard.js
const activityApi = require('../../../api/activity.js')
const util = require('../../../utils/util.js')

Page({
  data: {
    statistics: {
      total_activities: 0,
      pending_registrations: 0,
      total_registrations: 0,
      total_votes: 0
    },
    recentActivities: []
  },

  onLoad() {
    this.loadDashboardData()
  },

  onShow() {
    this.loadDashboardData()
  },

  async loadDashboardData() {
    try {
      // 加载统计数据（模拟）
      this.setData({
        statistics: {
          total_activities: 12,
          pending_registrations: 8,
          total_registrations: 156,
          total_votes: 892
        }
      })

      // 加载最近活动
      const res = await activityApi.getActivityList({ limit: 5 })
      if (res.code === 200) {
        this.setData({
          recentActivities: res.data.items
        })
      }
    } catch (error) {
      console.error('加载数据失败:', error)
    }
  },

  createActivity() {
    wx.navigateTo({
      url: '/pages/admin/activity/edit/edit'
    })
  },

  manageActivities() {
    wx.navigateTo({
      url: '/pages/admin/activity/manage/manage'
    })
  },

  reviewRegistrations() {
    wx.navigateTo({
      url: '/pages/admin/registration/list/list'
    })
  },

  monitorVotes() {
    wx.navigateTo({
      url: '/pages/admin/vote/monitor/monitor'
    })
  },

  viewStatistics() {
    wx.navigateTo({
      url: '/pages/admin/statistics/statistics'
    })
  },

  sendNotification() {
    util.showError('消息推送功能待实现')
  },

  goToActivity(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/activity/detail/detail?id=${id}`
    })
  }
})

